package power

import (
	"context"
	"time"

	"go-weixin/app/usercenter/api/internal/svc"
	"go-weixin/app/usercenter/api/internal/types"
	"go-weixin/app/usercenter/rpc/pb/proto/usercenter"

	"github.com/zeromicro/go-zero/core/logx"
)

type PowerDetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPowerDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PowerDetailLogic {
	return &PowerDetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PowerDetailLogic) PowerDetail(req *types.PowerDetailReq) (resp *types.PowerDetailResp, err error) {
	ctx, canelFunc := context.WithTimeout(context.Background(), 5*time.Second)
	defer canelFunc()
	res, err := l.svcCtx.UserRpc.PowerDetail(ctx, &usercenter.PowerDetailReq{
		Id: req.Id,
	})

	if err != nil {
		return nil, err
	}
	var powerInfo types.Power
	powerInfo.Id = res.PowerInfo.Id
	powerInfo.Name = res.PowerInfo.Name
	powerInfo.Url = res.PowerInfo.Url
	powerInfo.Method = res.PowerInfo.Method
	powerInfo.CreateAt = res.PowerInfo.CreateAt
	powerInfo.UpdateAt = res.PowerInfo.UpdateAt
	resp = new(types.PowerDetailResp)
	resp.PowerInfo = powerInfo
	return
}
